package pers.cj.pdos.controller.dialog;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import pers.cj.pdos.controller.GoodsSnController;
import pers.cj.pdos.controller.base.BaseController;
import pers.cj.pdos.entity.GoodsStock;
import pers.cj.pdos.entity.House;
import pers.cj.pdos.service.IGoodsStockService;
import pers.cj.pdos.service.IHouseService;
import pers.cj.pdos.utils.PdosUtils;
import pers.cj.pdos.utils.Utils;

@Controller
@RequestMapping("/dialog")
public class DialogController extends BaseController {
    @Autowired
    IHouseService houseService;
    @Autowired
    IGoodsStockService goodsStockService;

    /**
     *
     * @param model
     * @param goodsId 商品id
     * @param houseId 仓库id，当不传的时候，需要先进入选择仓库界面； 当传入仓库id的时候，则先进入序列号录入
     * @param type 1-商品编辑  2-其他（进货）
     * @return
     */
    @RequestMapping("/sn/import")
    public String snImport(Model model, String goodsId, String houseId, String type){
        model.addAttribute("goodsId",goodsId);
        model.addAttribute("houseVoList",houseService.listNormalVo(getCompany().getId(), PdosUtils.getViewHouseStoreId(getLoginUserVo(), null)));
        model.addAttribute("houseId",houseId);
        model.addAttribute("type",Utils.genInteger(type));
        return "/dialog/snImport";
    }


    @RequestMapping("/sn/select")
    public String snSelect(Model model, String goodsId, String houseId){
        model.addAttribute("goodsId",goodsId);
        model.addAttribute("houseVoList",houseService.listNormalVo(getCompany().getId(), PdosUtils.getViewHouseStoreId(getLoginUserVo(), null)));
        GoodsStock goodsStock = goodsStockService.getByGoodsAndHouse(goodsId,houseId);
        if (goodsStock == null) {
            model.addAttribute("stockNum", 0);
        } else {
            model.addAttribute("stockNum", goodsStock.getNum());
        }
        model.addAttribute("stock", goodsStockService.getByGoodsAndHouse(goodsId,houseId));
        model.addAttribute("house",houseService.getById(houseId));
        return "/dialog/snSelect";
    }

    @RequestMapping("/sn/checkHouse")
    public String checkHouse(Model model, String goodsId, String houseId){
        model.addAttribute("goodsId",goodsId);
        model.addAttribute("house",houseService.getById(houseId));
        return "/dialog/snCheckHouse";
    }


    @RequestMapping("/sn/goodsTransferSelect")
    public String goodsTransferSelect(Model model, String goodsTransferId, String goodsId){
        model.addAttribute("goodsTransferId",goodsTransferId);
        model.addAttribute("goodsId",goodsId);
        return "/dialog/goodsTransferSnSelect";
    }

    @RequestMapping("/sn/borrowInSelect")
    public String borrowInSelect(Model model, String borrowInId, String goodsId){
        model.addAttribute("borrowInId",borrowInId);
        model.addAttribute("goodsId",goodsId);
        return "/dialog/borrowInSnSelect";
    }

    @RequestMapping("/sn/borrowOutSelect")
    public String borrowOutSelect(Model model, String borrowOutId, String goodsId){
        model.addAttribute("borrowOutId",borrowOutId);
        model.addAttribute("goodsId",goodsId);
        return "/dialog/borrowOutSnSelect";
    }

    @RequestMapping("/house/lock")
    public String houseLock(){
        return "/dialog/houseLock";
    }
}
